package com.situ.ssm.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.situ.ssm.entity.PageInfo;
import com.situ.ssm.service.IStudentService;
import com.situ.ssm.service.impl.StudentServiceImpl;
import com.sun.corba.se.impl.logging.OMGSystemException;

@Controller
@RequestMapping(value = "/student")
public class StudentController {
	// private StudentService studentService = new StudentService();
	private IStudentService studentService = new StudentServiceImpl();

	@RequestMapping(value = "/findByPage")
	public String findByPage(@RequestParam(defaultValue = "1")Integer pageNo, 
			@RequestParam(defaultValue = "5")Integer pageSize, Model model) {
		System.out.println("StudentController.findByPage()");
		System.out.println("pageNo: " + pageNo);
		System.out.println("pageSize: " + pageSize);
		PageInfo pageInfo = studentService.findByPage(pageNo, pageSize);
		System.out.println(pageInfo);
		model.addAttribute("pageInfo", pageInfo);
		return "/student_list.jsp";
	}
	
	
	@RequestMapping(value = "/deleteById")
	public String deleteById(Integer id) {
		boolean isSuccess = studentService.deleteById(id);
		
		return "redirect:/student/findByPage.action";
	}
	
}
